// pages/akhexiao/akhexiao.js
const app = getApp();
const {
  getMiddleString
} = require('../../utils/jiequ');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    EMPLOYEE_ID: '',
    openid: '',
    jiami: '',
    OPEN_ID: '',
    session_key: '',
    fuwu: false,
  },



 // 复选框
 fuxk(event) {
  console.log(event.detail);
  this.setData({
    checked: event.detail,
  });
},

fuwu() {
  // this.setData({ show: true });
  this.setData({
    fuwu: !this.data.fuwu
  })
},











  gokehu(){
    wx.navigateTo({
      url: "/pages/newyueyeuxiangkehuchauxun/newyueyeuxiangkehuchauxun",
    })
  },

  saomiao() {

    this.setData({
      EMPLOYEE_ID: app.globalData.mealsList,
      openid: app.globalData.openid,

      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,


    });

    console.log(this.data.OPEN_ID);

    let that = this


    wx.scanCode({ //扫描API
      success(res) {
        console.log(res);
        console.log(res.result);


        // ajaj: '68581' + app.globalData.CUSTOMER_ID +'MUQZ4GaM_'+ text+ 'Ns1S2b7UX4k' + houtiex+'4AN9Y',

        // const text =  res.result.substring(0, 14);
        const yonghuid = getMiddleString(res.result, '68581', 'MUQZ4GaM_')
        const qianop = getMiddleString(res.result, 'MUQZ4GaM_', 'Ns1S2b7UX4k')
        const houop = getMiddleString(res.result, 'Ns1S2b7UX4k', '4AN9Y')



        if (res.result != '') {
          wx.request({
            url: app.globalData.interface+'/crossVersionOne/API2_2103_NewCustomerGiftsActivate',
            method: 'POST',
            data: {
              CODE: 'CUSTOMER_ID=' + yonghuid + '&' + 'openid=' + qianop + houop,
              EMPLOYEE_ID: that.data.EMPLOYEE_ID,
              OPEN_ID: that.data.OPEN_ID, //用户OPEN_ID
              session_key: that.data.session_key,
              OPEN_UUID: that.data.jiami
            },
            header: {
              'content-type': 'application/x-www-form-urlencoded'
            },
            success: res => {


              console.log(res)
              wx.showModal({
                title: '温馨提示',
                content: res.data.data,
                success: function (res) {
                  if (res.confirm) {//这里是点击了确定以后
                    console.log('用户点击确定')
                  } else {//这里是点击了取消以后
                    console.log('用户点击取消')
                  }
                }
              })
            }
          })
          //扫描成功
          // console.log(res) //输出回调信息
          // wx.showToast({
          //   title: '激活成功',
          //   duration: 2000
          // })
        } else {

          wx.showToast({
            title: '扫描失败请重新扫码',
            duration: 1000
          })

        }



        // this.ticket()
        // }
      }
    })

  },













  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(e) {
    console.log(e.data);

 
    

    this.setData({
      EMPLOYEE_ID: e.data,
      EMPLOYEE_ID: app.globalData.mealsList,
      openid: app.globalData.openid,

      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,


    })




  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})